﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Freetour.Application.Services.Membership;
using Freetour.Application.Models;
using Freetour.Application.Persistence.Repositories;
using Freetour.Application.Models.Membership;

namespace Freetour.Application.Services.Membership.Implements
{
    internal class MembershipServices : IMembershipServices
    {
        private IRepositoryFactory _repositoryFactory;

        public MembershipServices(IRepositoryFactory repositoryFactory)
        {
            this._repositoryFactory = repositoryFactory;
        }

        public MembershipServices()
            : this(new EFRepositoryFactory())
        {
        }

        public void Register(Models.Membership.MembershipEntity membership)
        {
            _repositoryFactory.Membership.Store(membership);
        }

        public bool Login(string userName, string password)
        {
            MembershipEntity membership = null;

            return _repositoryFactory.Membership.TryGetMembershipByName(userName, out membership);
        }

        public bool IsExistedMembership(string userName)
        {
            return _repositoryFactory.Membership.IsExistedMembership(userName);
        }
    }
}
